﻿$(document).ready(function () {
    $("#btnSave:first").click(function (e) {
        e.preventDefault();
        var lblMessage = $("#lblMessage:first").text("");
        $(".required:visible").each(function () {
            $(this).removeClass("ui-state-error");
            if ($(this).val() == "") {
                lblMessage.text("É necessário preencher os campos obrigatórios.");
                $(this).addClass("ui-state-error");
            }
        });

        if (lblMessage.text() == "") {
            $.ajax({
                dataType: "json",
                type: "POST",
                url: "/CostType/Save/" + $("#hdfIdCostType").val(),
                data: {
                    name: $("#txtName").val(),
                    value: $("#txtValue").val(),
                    description: $("#txtDescription").val()
                },
                success: function (json) {
                    document.location.href = "/CostType/Index";
                },
                error: function (json) {
                    jAlert("Erro", "Erro", function () { return false; });
                }
            });
        };
    });

    //$("#txtValue").maskMoney({ thousands: '.', decimal: ',', allowZero: true, showSymbol: false });
    $("#txtName:first").focus();
});